# coding=utf-8
import download
import httpclient
import config

from bs4 import BeautifulSoup

html = download.download("https://www.guazi.com/bj", 2)
soup = BeautifulSoup(html)
num = 0
list = []
for k in soup.find_all('a'):
    d = dict()
    num += 1
    try:
        if num >= 22:
            name = k.string.strip()
            url = k['href']
            d.setdefault("cityName", name)
            d.setdefault("cityUrl",url)
            list.append(d)
        if num == 169:
            break
    except:
        pass
httpclient.sendJson(list, config.getConfig('url', 'insertCity'))